// 定义用户相关信息的store
import { defineStore } from 'pinia';
import { computed, ref } from 'vue'
export const useUserStore = defineStore('user', () => {
    // 定义当前仓库中的数据
    // user 参数1: 相当于仓库的id, 代表仓库的唯一性 类似于 命名空间 namespaced:true
    // 01:相当于 state
    const userinfo = ref({
        name: '小黄',
        age: 24
    })
    const count = ref(0);

    // 02: 相当于actions
    const edituserFn = () => {
        setTimeout(() => {
            userinfo.value.name = '大杨嫂'
        }, 2000)

    };
    const addCount = () => {
        count.value++
    }

    // 03: 相当于getters
    const doubleCount = computed(() => {
        return count.value * 2
    })

    return {
        count,
        userinfo,
        edituserFn,
        addCount,
        doubleCount
    }
})